// export default usePersonHouseData;
import { reactive } from "vue";
import liaoning from "@/utils/liaoning.json";

const usePersonHouseData = (): any => {
  // 数据部分
  const personHouseData = reactive<any>({
    // 二手房销售价格指数统计
    priceIndexData: {},
    // 二手房交易面积及套数
    transactionData: {},
    // 二手房销售价格走势
    priceTrendData: {},
    // 二手住宅销售走势
    residentialTrendData: {},
    // 住宅租赁价格指数
    residentialRentPriceIndexData: {},
    // 二手房销售面积与价格
    andPriceData: {},
    // 各地区住房空置率走势
    housingVacancyRateData: {},
    // 中间地图
    personHouseMiddleData: {},
    dialogVisible: false,
    componentName: "",
    componentParams: {},
    cityName: "",
    cityCode: localStorage.getItem("cityCode"),
    data1: [], //1
    data2: [],
    data3: [],
    data4: [], //1
    data5: [],
    data6: [],
    data7: [],
  });

  let arr = liaoning.features.find((item: any) => item.properties.adcode == localStorage.getItem("cityCode"));
  const cityName = arr?.properties.name || "辽宁省";
  personHouseData.cityName = cityName;

  // 获取当前时间
  let date = new Date();
  let year = date.getFullYear();
  let month = date.getMonth() + 1;

  // 计算近三个月的时间范围
  let startTime = year + "-" + (month - 2 < 10 ? "0" + (month - 2) : month - 2);
  let endTime = year + "-" + (month < 10 ? "0" + month : month);

  // 设置默认时间范围
  if (personHouseData) {
    personHouseData.data1 = year + "-" + (month - 2 < 10 ? "0" + month : month);
    personHouseData.data2 = [startTime, endTime];
    personHouseData.data3 = year + "-" + (month - 2 < 10 ? "0" + month : month);
    personHouseData.data4 = [startTime, endTime];
    personHouseData.data5 = year + "-" + (month - 2 < 10 ? "0" + month : month);
    personHouseData.data6 = year + "-" + (month - 2 < 10 ? "0" + month : month);
    personHouseData.data7 = year + "-" + (month - 2 < 10 ? "0" + month : month);
  }
  return personHouseData;
};
export default usePersonHouseData;
